import logging
import random
import unittest

import requests
from parameterized import parameterized

from api.p2pApi import LoginApi
from common.read_json_util import read_json

# 获取图片验证码参数化
class TestImg_Parmeter(unittest.TestCase):
    def setUp(self) -> None:
        self.login_api = LoginApi()
        self.session = requests.session()

    def tearDown(self) -> None:
        self.session.close()
        # 引用参数化的数据
    @parameterized.expand(read_json("img.json"))
    def test01_img_parmeter(self,desc,type,status_code):
        if type == "decimal":
            r = random.random()
        elif type == "interger":
            r = random.randint(1000,99999)
        elif type == "kong":
            r = ""
        elif type == "charactor":
            r = "".join(random.sample("shwdyehuwjis",8))
        else:
            print("输入参数错误")
            # 调用api接口用参数名代替参数
        response = self.login_api.get_img_code(self.session,r)
        logging.info("打印返回结果{}".format(response))
        # 断言,打印日志可以在输出台看到结果
        self.assertEqual(status_code, response.status_code)

